package com.anolesoft.webService.impl;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.anolesoft.amljmes.delivery.deliwebservice.dto.MesBzzScjljhDto;
import com.anolesoft.amljmes.foreknow.bo.MesBzzZcbldmx;
import com.anolesoft.amljmes.foreknow.knowwebservice.dto.MesBzzFcfhjhDtoDao;
import com.anolesoft.amljmes.foreknow.knowwebservice.mapper.QjwlWebMapper;
import com.anolesoft.amljmes.foreknow.knowwebservice.service.QjwlWebService;
import com.anolesoft.amljmes.fortysix.controller.MesBzzFollowController;
import com.anolesoft.amljmes.fortysix.controller.MesBzzQtfxController;
import com.anolesoft.amljmes.fortysix.controller.MesBzzZcbldInfoController;
import com.anolesoft.amljmes.fortysix.dto.*;
import com.anolesoft.amljmes.fortysix.service.impl.*;
import com.anolesoft.amljmes.fortysix.service.mapper.AddPtdMapper;
import com.anolesoft.amljmes.fortysix.service.mapper.MesBzzCpptmxServiceMapper;
import com.anolesoft.amljmes.fortysix.service.mapper.PtckSpMapper;
import com.anolesoft.webService.inf.ErpWebService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.anolesoft.yr.demo.PageResult;

import javax.annotation.Resource;
import javax.jws.WebService;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@WebService(serviceName = "erpWebService",
        targetNamespace = "http://erp.webservice.com",
        endpointInterface = "com.anolesoft.webService.inf.ErpWebService"
)
@Component
public class WebServiceImpl implements ErpWebService{
    @Autowired
    MesBzzQtfxServiceImpl mesBzzQtfxService;
    @Autowired
    MesBzzCpptmxServiceImpl mesBzzCpptmxService;
    @Autowired
    MesBzzBindServiceImpl mesBzzBindService;
    @Autowired
    MesBzzFollowServiceImpl mesBzzFollowService;

    @Autowired
    MesBzzZcbldInfoServiceImpl mesBzzZcbldService;
    @Autowired
    MesBzzZcbldmxServiceImpl mesBzzZcbldmxService;

    @Autowired
    PtckSpMapper ptckSpMapper;
    @Autowired
    AddPtdMapper addPtdMapper;

    @Autowired
    private QjwlWebService qjwlWebService;
    @Resource
    private QjwlWebMapper mapper;

    @Autowired
    MesBzzCpptmxServiceMapper mesBzzCpptmxServiceMapper;

    @Override
    public String getHello1(String jsonObject) {
        System.out.println(jsonObject);
        return "helloword！";
    }

//    《《《《《《《《《《 配套分包 》》》》》》》》》》

    @Override
    public String getHelloPtmx(String jsonObject) {// 配套明细查询（ptbmx表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        String objuid = (obj.getString("objuid"));
        List<MesBzzPtdmxDto> list=mesBzzCpptmxService.queryMesBzzCpptmx(objuid);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Transactional
    @Override
    public String getUpdatePt(String jsonObject) {
        JSONArray jsonArray = JSONArray.parseArray(jsonObject.toString());
        List<PeiTaoVo> lists = JSONObject.parseArray(jsonArray.toJSONString(), PeiTaoVo.class);
        System.out.println(lists+"---------------------");
        PeiTaoVo map=lists.get(0);
        MesBzzFollowDto inFoDtoParam = new MesBzzFollowDto();
        inFoDtoParam.setPtdmxObj(map.getPtdmxObj());
        inFoDtoParam.setPaigonghao(map.getPaigonghao());
        inFoDtoParam.setJixing(map.getJixing());
        inFoDtoParam.setTuhao(map.getTuhao());
        inFoDtoParam.setJiaofuchejian(map.getJiaofuchejian());
        inFoDtoParam.setJieshouchejian(map.getJieshouchejian());
        inFoDtoParam.setJiaofushunxu(map.getJiaofushunxu());
        inFoDtoParam.setDingdanhao(map.getDingdanhao());
        inFoDtoParam.setPeitaodanhao(map.getPeitaodanhao());
        inFoDtoParam.setShuliang(map.getShulianng());
        inFoDtoParam.setFactoryId(map.getFactoryId());
        inFoDtoParam.setHegebiaoqian(map.getHegebiaoqian());
        // 需要在全景物流传登录人
        inFoDtoParam.setType(map.getType());
        inFoDtoParam.setFathername(map.getFathername());
        inFoDtoParam.setFathernumber(map.getFathernumber());
        inFoDtoParam.setPici(map.getPici());
        inFoDtoParam.setJiaci(map.getJiaci());
        inFoDtoParam.setProportion(map.getProportion());

        int a=mesBzzFollowService.addMesBzzFollow(inFoDtoParam);
        MesBzzBindDto inFoDtoParam1 = new MesBzzBindDto();
        int b=0;
        for(int i = 0; i < lists.size(); i++){
            inFoDtoParam1.setPtdObj(lists.get(i).getPtdObj());
            inFoDtoParam1.setPtdmxObj(lists.get(i).getPtdmxObj());
            inFoDtoParam1.setPaigonghao(lists.get(i).getPaigonghao());
            inFoDtoParam1.setJixing(lists.get(i).getJixing());
            inFoDtoParam1.setTuhao(lists.get(i).getTuhao());
            inFoDtoParam1.setJiaofuchejian(lists.get(i).getJiaofuchejian());
            inFoDtoParam1.setJieshouchejian(lists.get(i).getJieshouchejian());
            inFoDtoParam1.setJiaofushunxu(lists.get(i).getJiaofushunxu());
            inFoDtoParam1.setPeitaodanhao(lists.get(i).getPeitaodanhao());
            inFoDtoParam1.setFactoryId(lists.get(i).getFactoryId());
            inFoDtoParam1.setHegebiaoqian(lists.get(i).getHegebiaoqian());
            inFoDtoParam1.setDingdanbianhao(lists.get(i).getDingdanhao());
//            inFoDtoParam1.setBangdingren(loginUser.getEmpUid());
            inFoDtoParam1.setBangdingnum(lists.get(i).getBangdingnum());
            inFoDtoParam1.setKucunObj(lists.get(i).getKucunObj());
            inFoDtoParam1.setDanwei(lists.get(i).getDanwei());
            inFoDtoParam1.setDanjishu(lists.get(i).getDanjishu());
            inFoDtoParam1.setPici(lists.get(i).getPici());
            inFoDtoParam1.setJiaci(lists.get(i).getJiaci());
            if(lists.get(i).getBangdingnum()!=null){
                mesBzzBindService.addMesBzzBind(inFoDtoParam1);// 需要循环添加
                b++;
            }
        }

        String objuid = map.getObjuid();
        int num = 0;
        for(int i = 0; i < lists.size(); i++){
            if(lists.get(i).getBangdingnum()!=null){
                num+=lists.get(i).getBangdingnum();
            }
        }
        int c=mesBzzCpptmxService.updateCpptmxPt(objuid,num);
        int n = mesBzzCpptmxServiceMapper.queryMesBzzCpptmxNum(map.getPtdObj());
        if (n == 0) {
            mesBzzQtfxService.updateIsItComplete(map.getPtdObj());
        }
        if(a > 0 && b > 0 && c > 0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Transactional
    @Override
    public String getUpdateJc(String jsonObject) {
        JSONArray jsonArray = JSONArray.parseArray(jsonObject.toString());
        List<PeiTaoVo> lists = JSONObject.parseArray(jsonArray.toJSONString(), PeiTaoVo.class);
        System.out.println(lists+"---------------------");
        PeiTaoVo map=lists.get(0);
        MesBzzFollowDto inFoDtoParam = new MesBzzFollowDto();
        inFoDtoParam.setPtdmxObj(map.getPtdmxObj());
        inFoDtoParam.setPaigonghao(map.getPaigonghao());
        inFoDtoParam.setJixing(map.getJixing());
        inFoDtoParam.setTuhao(map.getTuhao());
        inFoDtoParam.setJiaofuchejian(map.getJiaofuchejian());
        inFoDtoParam.setJieshouchejian(map.getJieshouchejian());
        inFoDtoParam.setJiaofushunxu(map.getJiaofushunxu());
        inFoDtoParam.setDingdanhao(map.getDingdanhao());
        inFoDtoParam.setPeitaodanhao(map.getPeitaodanhao());
        inFoDtoParam.setShuliang(map.getShulianng());
        inFoDtoParam.setFactoryId(map.getFactoryId());
        inFoDtoParam.setHegebiaoqian(map.getHegebiaoqian());
        // 需要在全景物流传登录人
        inFoDtoParam.setType(map.getType());
        inFoDtoParam.setFathername(map.getFathername());
        inFoDtoParam.setFathernumber(map.getFathernumber());
        inFoDtoParam.setPici(map.getPici());
        inFoDtoParam.setJiaci(map.getJiaci());
        inFoDtoParam.setProportion(map.getProportion());
        int a=mesBzzFollowService.addMesBzzFollow(inFoDtoParam);
        String objuid = map.getObjuid();
        int num1 = 0;
        for(int i = 0; i < lists.size(); i++){
            if(lists.get(i).getJiechunum()!=null){
                num1+=lists.get(i).getJiechunum();
            }
        }
        int b=mesBzzCpptmxService.updateCpptmxJc(objuid,num1);
        int n = mesBzzCpptmxServiceMapper.queryMesBzzCpptmxNum(map.getPtdObj());
        if (n != 0) {
            mesBzzQtfxService.updateIsItComplete1(map.getPtdObj());
        }
        if(a > 0 && b > 0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

//    @Transactional
//    @Override
//    public String getUpdatePt(String jsonObject) {
//        System.out.println("11111111111111111111"+jsonObject);
//        JSONObject data = JSONObject.parseObject(jsonObject);
//        System.out.println("11111111111111111111"+data);
//        MesBzzFollowDto inFoDtoParam = new MesBzzFollowDto();
//        inFoDtoParam.setPtdmxObj(data.getString("ptdmxObj"));
//        inFoDtoParam.setPaigonghao(data.getString("paigonghao"));
//        inFoDtoParam.setJixing(data.getString("jixing"));
//        inFoDtoParam.setTuhao(data.getString("tuhao"));
//        inFoDtoParam.setJiaofuchejian(data.getString("jiaofuchejian"));
//        inFoDtoParam.setJieshouchejian(data.getString("jieshouchejian"));
//        inFoDtoParam.setJiaofushunxu(data.getString("jiaofushunxu"));
//        inFoDtoParam.setDingdanhao(data.getString("dingdanhao"));
//        inFoDtoParam.setPeitaodanhao(data.getString("peitaodanhao"));
//        inFoDtoParam.setShuliang(Integer.parseInt(data.getString("shulianng")));
//        inFoDtoParam.setFactoryId(data.getString("factoryId"));
//        inFoDtoParam.setHegebiaoqian(data.getString("hegebiaoqian"));
//        inFoDtoParam.setCaozuoren(data.getString("dqdlr"));
//        inFoDtoParam.setType(Integer.parseInt(data.getString("type")));
//        int a=mesBzzFollowService.addMesBzzFollow(inFoDtoParam);
//        MesBzzBindDto inFoDtoParam1 = new MesBzzBindDto();
//        inFoDtoParam1.setPtdObj(data.getString("ptdObj"));
//        inFoDtoParam1.setPtdmxObj(data.getString("ptdmxObj"));
//        inFoDtoParam1.setPaigonghao(data.getString("paigonghao"));
//        inFoDtoParam1.setJixing(data.getString("jixing"));
//        inFoDtoParam1.setTuhao(data.getString("tuhao"));
//        inFoDtoParam1.setJiaofuchejian(data.getString("jiaofuchejian"));
//        inFoDtoParam1.setJieshouchejian(data.getString("jieshouchejian"));
//        inFoDtoParam1.setJiaofushunxu(data.getString("jiaofushunxu"));
//        inFoDtoParam1.setPeitaodanhao(data.getString("peitaodanhao"));
//        inFoDtoParam1.setFactoryId(data.getString("factoryId"));
//        inFoDtoParam1.setHegebiaoqian(data.getString("hegebiaoqian"));
//        inFoDtoParam1.setDingdanbianhao(data.getString("dingdanhao"));
//        inFoDtoParam1.setBangdingren(data.getString("dqdlr"));
//        inFoDtoParam1.setBangdingnum(Integer.parseInt(data.getString("bangdingnum")));
//        inFoDtoParam1.setKucunObj(data.getString("kucunObj"));
//        int b=mesBzzBindService.addMesBzzBind(inFoDtoParam1);
//        String objuid = data.getString("objuid");
//        int num = Integer.parseInt(data.getString("num"));
//        int c=mesBzzCpptmxService.updateCpptmxPt(objuid,num);
//
//
//        if(a > 0 && b > 0 && c > 0){
//            return "修改成功";
//        }else {
//            return "修改失败";
//        }
//    }
//
//    @Transactional
//    @Override
//    public String getUpdateJc(String jsonObject) {
//        JSONObject data = JSONObject.parseObject(jsonObject);
//        MesBzzFollowDto inFoDtoParam = new MesBzzFollowDto();
//        inFoDtoParam.setPtdmxObj(data.getString("ptdmxObj"));
//        inFoDtoParam.setPaigonghao(data.getString("paigonghao"));
//        inFoDtoParam.setJixing(data.getString("jixing"));
//        inFoDtoParam.setTuhao(data.getString("tuhao"));
//        inFoDtoParam.setJiaofuchejian(data.getString("jiaofuchejian"));
//        inFoDtoParam.setJieshouchejian(data.getString("jieshouchejian"));
//        inFoDtoParam.setJiaofushunxu(data.getString("jiaofushunxu"));
//        inFoDtoParam.setDingdanhao(data.getString("dingdanhao"));
//        inFoDtoParam.setPeitaodanhao(data.getString("peitaodanhao"));
//        inFoDtoParam.setShuliang(Integer.parseInt(data.getString("shulianng")));
//        inFoDtoParam.setFactoryId(data.getString("factoryId"));
//        inFoDtoParam.setHegebiaoqian(data.getString("hegebiaoqian"));
//        inFoDtoParam.setCaozuoren(data.getString("dqdlr"));
//        inFoDtoParam.setType(Integer.parseInt(data.getString("type")));
//        int a=mesBzzFollowService.addMesBzzFollow(inFoDtoParam);
//        String objuid = data.getString("objuid");
//        int num1 = Integer.parseInt(data.getString("num1"));
//        int b=mesBzzCpptmxService.updateCpptmxJc(objuid,num1);
//        if(a > 0 && b > 0){
//            return "修改成功";
//        }else {
//            return "修改失败";
//        }
//    }


    @Override
    public String getHelloPtjcls(String jsonObject) {// 配套解除流水查询（follow表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        MesBzzFollowController.DemoVO demoVO = new MesBzzFollowController.DemoVO();
        demoVO.setPeitaodanhao(obj.getString("ptdh"));
        demoVO.setHegebiaoqian(obj.getString("hgbq"));
        demoVO.setType(obj.getInteger("lx"));
        List<MesBzzFollowDto> list = mesBzzFollowService.queryMesBzzFollowInfo(demoVO);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloPtfb(String jsonObject) {// 配套分包查询（ptb表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        MesBzzQtfxController.DemoVO demoVO = new MesBzzQtfxController.DemoVO();
        demoVO.setSupportingOrderNo(obj.getString("ptdh"));
        demoVO.setDispatch(obj.getString("bzzpgh"));
        demoVO.setFathernumber(obj.getString("fjh"));
        demoVO.setFathername(obj.getString("fjmc"));
        demoVO.setModel(obj.getString("jx"));
        demoVO.setBatch(obj.getString("pc"));
        demoVO.setSorties(obj.getString("jc"));
        demoVO.setProportion(obj.getString("bl"));
        demoVO.setFactoryCode(obj.getString("cdh"));
        List<MesBzzPtdDto> list = mesBzzQtfxService.queryMesBzzPtfbInfo(demoVO);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloWqt(String jsonObject) {// 修改未齐套（ptb表）
        System.out.println(jsonObject);
        String objuid = jsonObject.substring(0,jsonObject.length()-1);
        int a=mesBzzQtfxService.updateIsItComplete(objuid);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloYjj(String jsonObject) {// 已军检（ptb表）
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a=mesBzzQtfxService.updateMesBzzPtfb(asList);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloPtdy(String jsonObject) {// 配套单打印（ptb表）
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        List<MesBzzPtdDto> list = mesBzzQtfxService.querydmingxi(jsonObject);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloYjBj(String jsonObject) {// 查询已转场
         System.out.println(jsonObject);
         JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
         MesBzzQtfxController.DemoVO demoVO = new MesBzzQtfxController.DemoVO();
         demoVO.setSupportingOrderNo(obj.getString("ptdh"));
         demoVO.setDispatch(obj.getString("bzzpgh"));
         demoVO.setFathernumber(obj.getString("fjh"));
         demoVO.setFathername(obj.getString("fjmc"));
         demoVO.setModel(obj.getString("jx"));
         demoVO.setBatch(obj.getString("pc"));
         demoVO.setSorties(obj.getString("jc"));
         demoVO.setProportion(obj.getString("bl"));
         demoVO.setFactoryCode(obj.getString("cdh"));
         List<MesBzzPtdDto> list = mesBzzQtfxService.queryMesBzzQjbjInfo(demoVO);
         JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list));
         return jsonArray.toString();
    }


    @Override
    public String getHelloBind(String jsonObject) {// 绑定查询解除（bind表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        List<MesBzzBindDto> list=mesBzzBindService.queryMesBzzBind(obj.getString("objuid"));
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloBinds(String jsonObject) {// 绑定查询箱号检验（bind表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        List<MesBzzBindDto> list=mesBzzBindService.queryMesBzzBinds(obj.getString("objuid"));
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloDelete(String jsonObject) {// 删除bind
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a=mesBzzBindService.deleteMesBzzBind(asList);
        if(a>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @Override
    public String getHelloUpdete(String jsonObject) {// 修改bind
        System.out.println(jsonObject);
        JSONObject data = JSONObject.parseObject(jsonObject);
        String objuid = data.getString("objuid");
        int num1 = Integer.parseInt(data.getString("num1"));
        int a=mesBzzBindService.updateMesBzzBind(objuid,num1);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloState(String jsonObject) {// 配套单状态（bind表）
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        List<MesBzzBindDto> list = mesBzzBindService.queryState(jsonObject);
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloStateJy(String jsonObject) {// 检验状态（bind表）
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        int list = mesBzzBindService.queryStateJy(jsonObject);
        if(list<1){
            return "成功";
        }else {
            return "失败";
        }
    }

    @Override
    public String getHelloStateXh(String jsonObject) {// 检验状态（bind表）
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        int list = mesBzzBindService.queryStateXh(jsonObject);
        if(list<1){
            return "成功";
        }else {
            return "失败";
        }
    }

    @Override
    public String getHelloJy(String jsonObject) {// 状态为已检验（bind表）
        System.out.println(jsonObject);
        JSONObject data = JSONObject.parseObject(jsonObject);
        String objuid = data.getString("objuid");
        String jianyanren = data.getString("jianyanren");
        objuid = objuid.substring(1,objuid.length()-1).replace("\"","'");
        int a=mesBzzBindService.updateBindJystate(objuid,jianyanren);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloEmp(String jsonObject) {// 检验条码（emp表）
        List<BaoZhangZhuangEmpDTO> list = mesBzzBindService.queryEmpEid(jsonObject);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloXh(String jsonObject) {// 添加箱号（bind表）
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a=mesBzzBindService.updateBindXh(asList);
        if(a>0){
            return "添加箱号成功";
        }else {
            return "添加箱号失败";
        }
    }

    //    《《《《《《《《《《 配套出库 》》》》》》》》》》

    @Override
    public String getHelloZcbld(String jsonObject) {// 转场保留单查询（zcbld表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        MesBzzZcbldInfoController.DemoVO demoVO = new MesBzzZcbldInfoController.DemoVO();
        demoVO.setBaoliudanhao(obj.getString("bldh"));
        demoVO.setSupportingOrderNo(obj.getString("ptdh"));
        demoVO.setOrderNumber(obj.getString("ddbh"));
        demoVO.setFactoryCode(obj.getString("cdh"));
        List<MesBzzZcbldDto> list = mesBzzZcbldService.queryMesBzzZcbldInfo(demoVO);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloSwxxxs(String jsonObject) {// 实物信息显示
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        String supportingOrderNo = (obj.getString("supportingOrderNo"));
        List<MesBzzBindDto> list = mesBzzZcbldService.queryPtdBind(supportingOrderNo);
        // 加分页
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloBlddy(String jsonObject) {// 保留单打印
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(0,jsonObject.length()-1).replace("\"","'");
        List<MesBzzZcbldmxDto> list = mesBzzZcbldmxService.queryZcbldmx(jsonObject);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloYjddy(String jsonObject) {// 移交单打印
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        List<MesBzzBindDto> list = mesBzzZcbldmxService.queryBindYjd(jsonObject);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloBjddy(String jsonObject) {// 补件单打印
        System.out.println(jsonObject);
        jsonObject = jsonObject.substring(1,jsonObject.length()-1).replace("\"","'");
        List<MesBzzBindDto> list = mesBzzZcbldmxService.queryBindBjd(jsonObject);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloYjBjddy(String jsonObject) {// 移交补件单打印
        String str[] = jsonObject.split(",");
        List<YjBjDto> list = new ArrayList<YjBjDto>();
        for(int i = 0;i<str.length;i++){
            String objuid = str[i];
            List<YjBjDto> list_query = mesBzzZcbldmxService.queryBindYjBjd(objuid.trim());
            for(int j = 0;j<list_query.size();j++){
                YjBjDto yjBjDto = list_query.get(j);
                list.add(yjBjDto);
            }
        }
        System.out.println("list = " + list);
        JSONArray jsonArray1= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray1.toString();
    }

    @Override
    public String getHelloAddZcbldmxBz(String jsonObject) {// 根据保留单主键修改保留单明细备注
        System.out.println(jsonObject);
        JSONObject data = JSONObject.parseObject(jsonObject);
        String objuid = data.getString("objuid");
        String beizhu = data.getString("beizhu");

//        String[] str = jsonObject.split(",");
        newDto newDto = new newDto();
        newDto.setBeizhu(beizhu);
        newDto.setObjuid(objuid);
        int a=mesBzzZcbldmxService.updateZcbldBz(newDto);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<sjm>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    /**
     * 验证人员是否为检验岗位
     * @param
     * @return
     */
    @Override
    public String getMesJianyan(String jsonObject) {
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        String jytm = obj.getString("jytm");
        String fcode = obj.getString("fcode");
        String a = qjwlWebService.jianyan(jytm,fcode);
        String isRight = "false";
        if (a != null) {
            isRight = a;
        }
        return isRight;
    }

    /**
     * 有封存期的生成封存计划,有防护的生成防护计划
     * @param jsonObject
     * @return
     */
    @Transactional
    @Override
    public String getMesFengcunType(String jsonObject) {
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        MesBzzPtmlDto mesBzzPtmlDto = new MesBzzPtmlDto();
        // 如果order表中有数据,更改入库状态
        String orderid = obj.getString("orderid");
        int o = mapper.countorder(orderid);
        if (o != 0) {
            mapper.updateorder(orderid);
        }
        mesBzzPtmlDto.setJixing(obj.getString("jixing"));
        mesBzzPtmlDto.setTuhao(obj.getString("tuhao"));
        mesBzzPtmlDto.setJiaofuchejian(obj.getString("jfcj"));
        mesBzzPtmlDto.setJieshouchejian(obj.getString("jscj"));
        mesBzzPtmlDto.setJiaofushunxu(obj.getString("jfsx"));
        mesBzzPtmlDto.setJyr(obj.getString("jyr"));// 传过来的胸卡号
        mesBzzPtmlDto.setJsNum(Integer.parseInt(obj.getString("jsnum")));
        mesBzzPtmlDto.setChangdaihao(obj.getString("fcode"));
        mesBzzPtmlDto.setKucunzhujian(obj.getString("kucunzhujian"));
        mesBzzPtmlDto.setHgbqbh(obj.getString("hgbqbh"));
        String fengcun = null;
        // 判断是否有数据
        int z = mapper.countPtml(mesBzzPtmlDto);
        if (z == 0) {
            fengcun = "暂未获取";
        } else {
            MesBzzPtmlDto ptmlDto = qjwlWebService.toPtml(mesBzzPtmlDto);
            // 是否做防护,封存(判断)
            if (ptmlDto.getShifouzuofanghu() == 1) {
                MesBzzFcfhjhDtoDao dto = new MesBzzFcfhjhDtoDao();
                dto.setQualifiedLabelNumber(obj.getString("hgbqbh"));
                dto.setPlanType(1);
                String dd = obj.getString("bgq");
                dto.setFanghuTime(dd);
                dto.setSealingMethod(ptmlDto.getFengcunfangfa());
                dto.setInternalDivisionOfLabor(ptmlDto.getNeibufengong());
                if (ptmlDto.getFengcunleixing() != null) {
                    dto.setSealType(ptmlDto.getFengcunleixing() + 1);
                } else {
                    dto.setSealType(0);
                }
                dto.setState(0);
                dto.setCUser(obj.getString("jyr"));// 传过来的胸卡号
                dto.setFactory(obj.getString("fcode"));
                dto.setRukuren(obj.getString("jyr")); // 传过来的胸卡号
                dto.setPaigonghao(obj.getString("pgh"));
                dto.setMingcheng(obj.getString("partname"));
                dto.setJixing(obj.getString("jixing"));
                dto.setTuhao(obj.getString("tuhao"));
                dto.setJiaofuchejian(obj.getString("jfcj"));
                dto.setJieshouchejian(ptmlDto.getJieshouchejian());
                dto.setJiaofushunxu(ptmlDto.getJiaofushunxu());
                dto.setKucunObjuid(obj.getString("kucunzhujian"));
                dto.setShuliang(Integer.parseInt(obj.getString("jsnum")));
                dto.setDw(obj.getString("dw"));
                dto.setPc(obj.getString("pc"));
                dto.setJc(obj.getString("jc"));
                // 第二次入库时不需要再次生成防护计划  加入判断是否存在一条防护计划
                int c = mapper.countfh(dto);
                if (c == 0) {
                    int a = qjwlWebService.insertFcfhjhfanghu(dto);
                }
            }
            // 操作封存防护计划表
            MesBzzFcfhjhDtoDao dtoDao = new MesBzzFcfhjhDtoDao();
            dtoDao.setQualifiedLabelNumber(obj.getString("hgbqbh"));
            dtoDao.setPlanType(0);
            String dd = obj.getString("yfq");
            dtoDao.setExpirationTime(dd);
            dtoDao.setSealingMethod(ptmlDto.getFengcunfangfa());
            dtoDao.setInternalDivisionOfLabor(ptmlDto.getNeibufengong());
            if (ptmlDto.getFengcunleixing() != null) {
                dtoDao.setSealType(ptmlDto.getFengcunleixing() + 1);
            } else {
                dtoDao.setSealType(0);
            }
            dtoDao.setState(0);
            dtoDao.setCUser(obj.getString("jyr"));// 传过来的胸卡号
            dtoDao.setFactory(obj.getString("fcode"));
            dtoDao.setRukuren(obj.getString("jyr"));// 传过来的胸卡号
            dtoDao.setPaigonghao(obj.getString("pgh"));
            dtoDao.setMingcheng(obj.getString("partname"));
            dtoDao.setJixing(obj.getString("jixing"));
            dtoDao.setTuhao(obj.getString("tuhao"));
            dtoDao.setJiaofuchejian(obj.getString("jfcj"));
            dtoDao.setJieshouchejian(ptmlDto.getJieshouchejian());
            dtoDao.setJiaofushunxu(ptmlDto.getJiaofushunxu());
            dtoDao.setKucunObjuid(obj.getString("kucunzhujian"));
            dtoDao.setDw(obj.getString("dw"));
            dtoDao.setPc(obj.getString("pc"));
            dtoDao.setJc(obj.getString("jc"));
            dtoDao.setShuliang(Integer.parseInt(obj.getString("jsnum")));
            int a = qjwlWebService.insertFcfhjhfengcun(dtoDao);
            if (ptmlDto.getFengcunleixing() == 0){
                fengcun = "1";
            }else {
                fengcun = "2";
            }
        }
        return fengcun;
    }
//            String baoguan = obj.getString("bgq");
//            DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//            LocalDate date = LocalDate.parse(baoguan, fmt);   + " 00:00:01"
//            LocalDate localDate = obj.getDate("bgq").toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

    /**
     * 根据制造记录获取合格标签条码(内部封存出库)
     * @param zzjltm
     * @return
     */
    @Override
    public String getMesHgbqtm(String zzjltm) {
        String hgbq = qjwlWebService.hgbqtm(zzjltm);
        return hgbq;
    }

    /**
     * 修改封存防护计划状态
     * @param jsonObject
     */
    @Override
    public void updateFcfhjh(String jsonObject) {
//        String jsonObjectStr = jsonObject.toString();
        JSONObject data = JSONObject.parseObject(jsonObject);
        JSONArray jsonArray = JSONArray.parseArray(data.getString("hgbqtm"));
        String wcr = data.getString("wcr");
//        System.out.println("_______________________________" + jsonArray);
        List<String> hgbqbh = JSONObject.parseArray(jsonArray.toJSONString(), String.class);
        int a  = qjwlWebService.updateFcfhjh(hgbqbh, wcr);
    }

    /**
     * 根据合格标签条码获取order和fcfhjh的数据(内部封存入库)
     * @param hgbqtm
     * @return
     */
    @Override
    public String getDataByHgbqbm(String hgbqtm) {
        return qjwlWebService.getDataByhgbq(hgbqtm);
    }

    @Override
    public String zhuxiaofcfhjh(String hgbqtm) {
        List<String> list = new ArrayList<>();
        list.add(hgbqtm);
        int a = mesBzzZcbldmxService.updateStateZx(list);
        return a + "";
    }


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<调用多个方法配套出库>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    @Transactional
    @Override
    public String getJsonObject(String jsonObject) {
        JSONObject data = JSONObject.parseObject(jsonObject);
        String objuid= data.getString("dlrobjuid");
        int a=0;
        int b=0;
        String z=null;
        // 实物绑定状态变成“转场”,生成移交单号
        String ptdh = data.getString("ptdh");
        a=mesBzzZcbldService.updateBindStateZc(ptdh,objuid);
        // 配套单状态变为“已转场”
        if (a>0) {
            int e=mesBzzZcbldService.updatePtdStateZc(ptdh);
        }
        // 实物绑定状态变成“补件”,生成补件单号
        b=mesBzzZcbldService.updateBindStateBj(ptdh);



        // 根据配套单条码查缺件数量不等于0的
        List<MesBzzBindDto> list = mesBzzZcbldService.queryPtdmxQjs(ptdh);
        if (list.size()==0){
            z="不缺件";
        }else {
            z="缺件";
            for (MesBzzBindDto obj: list) {
                String BldoObjuid = IdUtil.simpleUUID();
                // 生成转场保留单
                MesBzzZcbldDto mesBzzZcbldDto=new MesBzzZcbldDto();
                mesBzzZcbldDto.setObjuid(BldoObjuid);
                mesBzzZcbldDto.setModel(obj.getJixing());
                mesBzzZcbldDto.setJiaci(obj.getJiaci());
                mesBzzZcbldDto.setPtdid(obj.getPtdObj());
                mesBzzZcbldDto.setYijiaodanwei(obj.getJiaofuchejian());
                mesBzzZcbldDto.setYijiaoren(obj.getYijiaoren());
                mesBzzZcbldDto.setJieshoudanwei(obj.getJieshouchejian());
                mesBzzZcbldDto.setJieshoudaibiao(objuid);
                mesBzzZcbldDto.setFactoryCode(obj.getFactoryId());
                mesBzzZcbldDto.setCreatName(objuid);

                int f=mesBzzZcbldService.addMesBzzZcbld(mesBzzZcbldDto);

                // 生成转场保留单明细
                MesBzzZcbldmxDto mesBzzZcbldmxDto=new MesBzzZcbldmxDto();
                mesBzzZcbldmxDto.setBldobjuid(BldoObjuid);
                mesBzzZcbldmxDto.setPtdmxid(obj.getPtdmxObj());
                mesBzzZcbldmxDto.setName(obj.getName());
                mesBzzZcbldmxDto.setModel(obj.getJixing());
                mesBzzZcbldmxDto.setDanwei(obj.getDanwei());
                mesBzzZcbldmxDto.setBili(obj.getProportion());
                if (obj.getDanjishu() != null) {
                    mesBzzZcbldmxDto.setDanjishu(Integer.parseInt(obj.getDanjishu()));
                }
                mesBzzZcbldmxDto.setQuejianshu(obj.getQuantityOfMissingParts());
                mesBzzZcbldmxDto.setZerendanwei(obj.getJiaofuchejian());
                mesBzzZcbldmxDto.setBeizhu("");
                mesBzzZcbldmxDto.setPtdid(obj.getPtdObj());

                int g=mesBzzZcbldmxService.addMesBzzZcbldmx(mesBzzZcbldmxDto);
            }

        }

        String dengyu = data.getString("dengyu");
        if (dengyu.length()!=0) {
            String[] str3 = dengyu.split(",");
            List<String> asList3 = null;
            if (jsonObject != null) {
                asList3 = Arrays.asList(str3);
            }
            int h=mesBzzZcbldmxService.updateStateZx(asList3);
        }

        String budengyu = data.getString("budengyu");
        String jsonObjectStr = budengyu.toString();
        JSONArray jsonArray = JSONArray.parseArray(jsonObjectStr);
        List<BudengyuDto> dto = JSONObject.parseArray(jsonArray.toJSONString(), BudengyuDto.class);

        int j=mesBzzZcbldmxService.updateNumJs(dto);

        return z;
    }

//    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<配套出库审批   lx>>>>>>>>>>>>>>>>>>>>>>>>>>

    @Override
    public String getHelloYbh(String jsonObject) {// 已驳回（ptb表）
        System.out.println(jsonObject);
        String objuid = jsonObject.substring(0,jsonObject.length()-1);
        int a=ptckSpMapper.updateMesBzzBh(objuid);
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloPtdmx(String jsonObject) {// 配套明细查询（ptbmx表）
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        String objuid = (obj.getString("objuid"));
        List<MesBzzPtdmxDto> list=ptckSpMapper.queryMesBzzptdmx(objuid);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }



    @Override
    public String getHelloSp(String jsonObject) {// 待审批
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a = 0;
        for(String objuid : asList) {
            a = ptckSpMapper.updateSp(objuid);
        }
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloCh(String jsonObject) {// 撤回
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a = 0;
        for(String objuid : asList) {
            a = ptckSpMapper.updateCh(objuid);
        }
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloTg(String jsonObject) {// 通过
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a = 0;
        for(String objuid : asList) {
            a = ptckSpMapper.updateTg(objuid);
        }
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloBh(String jsonObject) {// 驳回
        System.out.println(jsonObject);
        String[] str = jsonObject.split(",");
        List<String> asList = null;
        if (jsonObject != null) {
            asList = Arrays.asList(str);
        }
        int a = 0;
        for(String objuid : asList) {
            a = ptckSpMapper.updateBh(objuid);
        }
        if(a>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @Override
    public String getHelloPtckTs(String jsonObject) {// 绑定
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        PtckSpVo demoVO = new PtckSpVo();
        demoVO.setFathernumber(obj.getString("fjh"));
        demoVO.setSupportingOrderNo(obj.getString("ptdh"));
        demoVO.setModel(obj.getString("jx"));
        demoVO.setBatch(obj.getString("pc"));
        demoVO.setSorties(obj.getString("jc"));
        demoVO.setAffiliation(obj.getString("sszy"));
        demoVO.setFactorycode(obj.getString("cdh"));
        List<PtckSpDto> list = ptckSpMapper.queryMesBzzTsSQL(demoVO);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloPtckSp(String jsonObject) {// 审批
        System.out.println(jsonObject);
        JSONObject obj = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        PtckSpVo demoVO = new PtckSpVo();
        demoVO.setFathernumber(obj.getString("fjh"));
        demoVO.setSupportingOrderNo(obj.getString("ptdh"));
        demoVO.setModel(obj.getString("jx"));
        demoVO.setBatch(obj.getString("pc"));
        demoVO.setSorties(obj.getString("jc"));
        demoVO.setAffiliation(obj.getString("sszy"));
        demoVO.setFactorycode(obj.getString("cdh"));
        List<PtckSpDto> list = ptckSpMapper.queryMesBzzSpSQL(demoVO);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }

    @Override
    public String getHelloPtdbs(String jsonObject) {
        System.out.println(jsonObject);
        JSONObject cdh = com.alibaba.fastjson.JSON.parseObject(jsonObject);
        String factoryCode = (cdh.getString("cdh"));
        List<PtdbsDto> list= addPtdMapper.queryPtdbs(factoryCode);
        JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
        return jsonArray.toString();
    }
}
